﻿using Dapper;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PoemGame.Query.Dapper
{
    public class GameQuery:IGameQuery
    {
        private readonly IDbConnection connection;

        public GameQuery(IDbConnection connection)
        {
            this.connection = connection;
        }

        public async Task<GameRes?> GetGameResAsync(Guid gameId)
        {
            return await connection.GetAsync<GameView>(gameId);
        }

        public async Task<IEnumerable<GameRes>> GetGamesByConditionAsync(string wherecondition)
        {
            return await connection.GetListAsync<GameView>(wherecondition); ;
        }

        public async Task<IEnumerable<GameRes>> GetPagedGamesByConditionAsync(int pageindex, int pagesize, string wherecondition, string orderby)
        {
            return await connection.GetListPagedAsync<GameView>(
                pageindex, pagesize, wherecondition, orderby);
        }

        public async Task<long> GetGamesCountByConditionAsync(string wherecondition)
        {
            return await connection.RecordCountAsync<GameView>(wherecondition);
        }
    }
}
